<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

class AddToCollection extends BatchAction
{
    protected $cid;

    public function __construct($cid = 1)
    {
        $this->cid = $cid;
    }
    
    public function script()
    {
        $route = route("collection_articles.batch_add", ['cid' => $this->cid]);
        return <<<EOT
        
$('{$this->getElementClass()}').on('click', function() {
    $.ajax({
        method: 'post',
        url: '{$route}',
        data: {
            _token:'{$this->getToken()}',
            ids: sSelectedRows()
        },
        success: function (res) {
            console.log(res)
            $.pjax.reload('#pjax-container');
            toastr.success('操作成功');
        }
    });
});

EOT;

    }
}
